How to solve these coding challenges:
Write your solution in PyCharm or in your preferred Python IDE.
If your solution is not correct, then try to understand the error messages, watch the video again, rewrite the solution, and test it again. Repeat this step until you get the correct solution.
Save the solution in a file for future reference or recap.
Challenge #1
A. Declare variables for the following types: int, float, bool, string, list.
B. Print out the variables and their types at the terminal.
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #2
Change this script so that it follows the Python naming and style conventions described in PEP8.
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #3
This script contains some syntax errors. Modify the script so that it runs without any errors.
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #4
Create a new Python script that uses the following operators: =, ==, >=, *, **, /, //, %, +=, *=
Are you stuck? Do you want to see the solution to this exercise? Click here
Challenge #5
Consider the following Python expression: a = 16 / 2 + 6 / 2 ** 2
Add parenthesis to change the order of operations so that a is 1.0
Are you stuck? Do you want to see the solution to this exercise? Click here
Challenge #6
An IPv6 address is represented using 128 bits.
Write a Python script that calculates how many IPv6 addresses are available. You can also include reserved IP addresses.
Are you stuck? Do you want to see the solution to this exercise? Click here
Challenge #7
A company's revenue is 45,897,513.
Calculate the company's profit if the profit represents 12.7% of the revenue.
Display the profit using 2 decimal places.
Are you stuck? Do you want to see the solution to this exercise? Click here
Challenge #8
A junior Python programmer writes the following code snippet and gets surprised that the comparison operator returns False instead of True.
a = 0.1 b = 0.3 print(a * 3 == b) # => False
Your job is to modify the code so that the comparison returns True which is correct.
Are you stuck? Do you want to see the solution to this exercise? Click here